/**
 * AtolCD/Spatialytics/widgets/DialogManager.js
 *
 * Dialog Box Manager
 *
 * Copyright (C) 2008-2009 GeoSOA Research Group, Universite Laval
 * See LICENSE file under this distribution for licensing information
 * 
 * @author Vincent Plantegenet
 * @since 201004
 **/


dojo.provide("AtolCD.Spatialytics.DialogManager");

dojo.require("dijit._Widget");
dojo.require("dijit.Dialog");

AtolCD.Spatialytics.DialogManager = function (options) {
	
	this._Dlg = [];
	this.cpt = 0;
	this.message = options.message;

	options.onObs.register(this.getNewDialObserver());
	options.offObs.register(this.getOlapAjaxObserver());
}

AtolCD.Spatialytics.DialogManager.prototype.make = function () {
	
	var that = this;
	
	that.cpt++;
	
	that._Dlg[that.cpt] = new dijit.Dialog({
						title: "Loading",
						style: "width: 300px",
						draggable: false
					});
				
	that._Dlg[that.cpt].attr("content", that.message);
	that._Dlg[that.cpt].show();
	
	return that.cpt;
}
AtolCD.Spatialytics.DialogManager.prototype.unmake = function () {
	for(var i in that._Dlg){
				that._Dlg[i].hide();
			}
}
AtolCD.Spatialytics.DialogManager.prototype.getOlapAjaxObserver = function () {
	var that = this;
	
	var closure = function (olapAjax) {

		for(var i in that._Dlg){
			that._Dlg[i].hide();
		}

	};
	
	return closure;
};

AtolCD.Spatialytics.DialogManager.prototype.getNewDialObserver = function () {
	var that = this;
	
	var closure = function (olapAjax) {

		that.make();

	};
	
	return closure;
};
